package site.wetsion.galio.auth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import site.wetsion.galio.auth.filter.UserFilter;

import javax.sql.DataSource;

/**
 * @author weixin
 * @version 1.0
 * @CLassName BeanConfig
 * @date 2019/5/15 7:46 PM
 */
@Configuration
public class BeanConfig {

    @Qualifier("dataSource")
    @Autowired
    private DataSource dataSource;

    @Bean
    public FilterRegistrationBean buildUserFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new UserFilter(dataSource));
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.addUrlPatterns("/rms/user/*");
        return filterRegistrationBean;
    }
}
